package HomeWork.Question4;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.SocketException;

class Server_Thread implements Runnable {
    Server s;
    Server_Thread(Server s){
        this.s = s;
    }
    @Override
    public void run() {
        try {
            s.receive();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

class Client_Thread implements Runnable{
    Client c;
    Client_Thread(Client c){
        this.c = c;
    }
    @Override
    public void run() {
        try {
            c.send();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

class Chat_Thread{
    private final int server_port;
    private final int send_port;
    protected Chat_Thread(int server_port,int send_port){
        this.server_port = server_port;
        this.send_port = send_port;
    }
    protected void start_chat() throws SocketException {
        DatagramSocket datagramSocket = new DatagramSocket(server_port);
        new Thread(new Server_Thread(new Server(datagramSocket))).start();
        new Thread(new Client_Thread(new Client(send_port,datagramSocket))).start();
    }
}